﻿

#pragma once

#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stdexcept>
#include <assert.h>

#include "IniKeyValue.h"


#pragma warning(push) 
#pragma warning( disable : 4290 )
#pragma warning( disable : 4996 )

namespace ksini
{




	//! \brief  section for ini-file.
	class IniSection 
	{
	private:

		std::string m_sname;
		std::string m_sCommentLine;
		std::vector<IniKeyValue> m_vector_keyval;

	public:

		IniSection(const std::string& sname, const std::string& commentLine) throw(std::runtime_error);

		~IniSection() 
		{ 
			m_vector_keyval.clear(); 
		}

		//! set section name
		const std::string& getSectionName() const 
		{ 
			return m_sname; 
		}

		//! \brief  add key and value;
		IniKeyValue* addKeyValue(const std::string& skey, const std::string& svalue, const std::string& sComment) ;

		IniKeyValue* addKeyValue(const IniKeyValue& kv);

		IniSection*  addSection(const std::string& sSection);

		bool searchKey(  int& index , const std::string& sKey) const;

		bool isKeyExests(const std::string& sKey);

		int getNumKeys() const 
		{ 
			return (int)m_vector_keyval.size(); 
		}

		IniKeyValue&  getKeyValueByIndex(const int index) throw(std::runtime_error&);

		const IniKeyValue&  getKeyValueByIndex(const int index) const  throw(std::runtime_error&);

		void clearAll() 
		{ 
			m_vector_keyval.clear(); 
		}


		std::string getCommentLine() const 
		{
			return m_sCommentLine;
		}

		void make_keyvalue_text(std::string& dest, bool includeComments) const;

		void make_full_inisection_text(std::string& dest) const;


	};



}


#pragma warning(pop) 
